part of YFree;

extension YPage_Broadcast on YPage {
  void yBroadcast_register(String action, Function(Map<String, dynamic>? map) callback) {
    _broadcastReceivers[action] = callback;
  }

  void yBroadcast_send(String action, {Map<String, dynamic>? params}) {
    for (var yPage in yPages) {
      try {
        yPage._broadcastReceivers[action]?.call(params);
      } catch (e) {}
    }
  }

  void yBroadcast_unregister(String action) {
    _broadcastReceivers.remove(action);
  }

  void yBroadcast_unregisters() {
    try {
      _broadcastReceivers.forEach((key, value) => yBroadcast_unregister(key));
    } catch (e) {}
    _broadcastReceivers.clear();
  }
}
